package com.test.webdemo.bean;

import com.test.webdemo.servlet.TrackableViewResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc  // 启用 Spring MVC 注解驱动
@ComponentScan(basePackages = "com.test.webdemo")  // 扫描你的包
public class AppConfig implements WebMvcConfigurer {

    // 显式注册 Servlet API 相关 Bean（解决 NoClassDefFoundError）
    @Bean
    public javax.servlet.ServletContext servletContext() {
        return new MockServletContext();  // 仅用于测试环境
    }

    // 其他 MVC 配置（如视图解析器、拦截器等）
    @Bean
    public TrackableViewResolver viewResolver() {
        TrackableViewResolver resolver = new TrackableViewResolver();
        resolver.setPrefix("/WEB-INF/jsp/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
}
